package Aleehot100;

/**
 * ClassName: c021
 * Package: Aleehot100
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/6/11 21:41
 * @Version 1.0
 * @Since 1.0
 */
public class c021 {
    public static void main(String[] args) {
        int[][] arr = {{1,4,7,11,15},{2,5,8,12,19},{3,6,9,16,22},{10,13,14,17,24},{18,21,23,26,30}};
        System.out.println(searchMatrix(arr, 20));
    }


    /**
     * 从左下角开始遍历 ， 可以画一下图， 就是贪心算法
     * @param matrix
     * @param target
     * @return
     */
    public static boolean searchMatrix(int[][] matrix, int target) {
        int row = matrix.length - 1, col = 0;
        while(row >= 0 && col <= matrix[0].length - 1) {
            if(matrix[row][col] > target) {
                row --;
            } else if(matrix[row][col] < target){
                col ++;
            } else {
                return true;
            }
        }
        return false;
    }

}
